package com.cskaoyan.util;

import java.util.Random;

/**
 * @author: DYQ
 * @time: Created on 2022/6/8 20:10
 */
public class CodeUtils {

    public static String getRandomString(int length) {
        Random random = new Random();
        String numbers = "0123456789";
        // create a super set of all characters
        String allCharacters = numbers;
        // initialize a string to hold result
        StringBuffer randomString = new StringBuffer();
        // loop for 10 times
        for (int i = 0; i < length; i++) {
            // generate a random number between 0 and length of all characters
            int randomIndex = random.nextInt(allCharacters.length());
            // retrieve character at index and add it to result
            randomString.append(allCharacters.charAt(randomIndex));
        }
        return randomString.toString();
    }
}
